<html>
    <head>
        <title>Sistema de Pedidos</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">-->
        <link rel='stylesheet' href='bootstrap-3.3.1/dist/css/bootstrap.css'>
        <script language="javascript" type="text/javascript">
            function iniciaAjax() {
                var objetoAjax = false;
                if (window.XMLHttpRequest) {
                    objetoAjax = new XMLHttpRequest();
                } else if (window.ActiveXObject) {
                    try {
                        objetoAjax = new ActiveXObject("Msxm12.XMLHTTP");
                    } catch (e) {
                        try {
                            objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (ex) {
                            objetoAjax = false;
                        }
                    }
                }
                return objetoAjax;
            }

            var ini = iniciaAjax();


            function consultar() {
                var nome = document.getElementById("nome").value;
                var codigo = document.getElementById("codigo").value;
                var url = "http://localhost:8080/SistemaPedido/consulta?nome=" + nome;
                ini.open("GET", url, true);
                ini.onreadystatechange = callback;
                ini.send(null);
            }

            function callback() {
                if (ini.readyState === 4) {
                    if (ini.status === 200) {
                        document.getElementById("respostaServidor").innerHTML = ini.responseText;
                    }
                }
            }
            function redirecionaCadastra() {
                window.location = 'CadastrarPedido.html';
            }
        </script>
    </head>
    <body>
        <div>
            <h1>
                Sistema de Pedidos
            </h1>
            <div>
                <input type="button" value="Cadastrar Pedido" name="btnCadastrarPedido" onclick="redirecionaCadastra();" />
            </div>
            <div>
                <h1>Buscar Pedidos</h1>
                <label>Nome:</label><input type="text" id="nome"  />
                <label>Codigo:</label><input type="text" id="codigo"  />
                <input type="button" value="Buscar" onclick="consultar();" />
                <div id="respostaServidor">
                </div>
            </div>            
        </div>
    </body>
</html>
